// owner-app/pages/my-live/index.js
import { handlerGobackClick, hint } from "../../../utils/util";
const app = getApp();
import Apipublic from "../../../models/api";
const apipublic = new Apipublic();
import User from "../../../models/user";
const user = new User();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    baseImgUrl: "",
    records: {
      marriageStatusDesc: "",
      politicalOutlookDesc: "",
      healthDesc: "",
      faithDesc: "",
      educationDesc: "",
      college: "",
      remark: "",
      major: "",
      workUnit: "",
      jobTypeDesc: "",
      job: "",
    },
    marriageStatusShow: false,
    politicalOutlookShow: false,
    healthShow: false,
    faithShow: false,
    economicsShow: false,
    educationShow: false,
    jobTypeShow: false,
    columnsMarriageStatus: [],
    columnsPoliticalOutlook: [],
    columnsHealth: [],
    columnsFaith: [],
    columnsEconomics: [],
    columnEducation: [],
    columnJobType: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var { baseImgUrl } = getApp().globalImgUrl.config;
    this.setData({
      baseImgUrl,
    });
    this.initPageData();
    this.classify();
  },
  handlerGobackClick,
  // 控制选择框显示隐藏
  handleShowPicker(e) {
    var showflag = e.currentTarget.dataset.showflag;
    var { showname } = e.currentTarget.dataset;
    if (!showflag) {
      this.setData({
        [showname]: false,
      });
      return false;
    }

    this.setData({
      [showname]: JSON.parse(e.currentTarget.dataset.showflag),
    });
  },
  onChange(e) {
    let key = e.currentTarget.dataset.key;
    let value = e.detail;
    this.setData({
      [key]: value,
    });
  },
  marriageStatusConfirm(e) {
    this.setData({
      ["records.marriageStatus"]: e.detail.value.value,
      ["records.marriageStatusDesc"]: e.detail.value.text,
      marriageStatusShow: false,
    });
  },
  politicalOutlookConfirm(e) {
    this.setData({
      ["records.politicalOutlook"]: e.detail.value.value,
      ["records.politicalOutlookDesc"]: e.detail.value.text,
      politicalOutlookShow: false,
    });
  },
  healthConfirm(e) {
    this.setData({
      ["records.health"]: e.detail.value.value,
      ["records.healthDesc"]: e.detail.value.text,
      healthShow: false,
    });
  },
  faithConfirm(e) {
    this.setData({
      ["records.faith"]: e.detail.value.value,
      ["records.faithDesc"]: e.detail.value.text,
      faithShow: false,
    });
  },
  economicsConfirm(e) {
    this.setData({
      ["records.economics"]: e.detail.value.value,
      ["records.economicsDesc"]: e.detail.value.text,
      economicsShow: false,
    });
  },
  educationConfirm(e) {
    this.setData({
      ["records.education"]: e.detail.value.value,
      ["records.educationDesc"]: e.detail.value.text,
      educationShow: false,
    });
  },
  jobTypeConfirm(e) {
    this.setData({
      ["records.jobType"]: e.detail.value.value,
      ["records.jobTypeDesc"]: e.detail.value.text,
      jobTypeShow: false,
    });
  },
  submit() {
    user.basicInformationSub(this.data.records).then((res) => {
      if (res.code == 1000) {
        hint("保存成功");
        setTimeout(() => {
          wx.navigateBack();
        }, 1000);
      }
    });
  },
  initPageData() {
    user.basicInformation().then((res) => {
      if (res.code == 1000) {
        this.setData({
          records: res.result,
        });
      }
    });
  },
  classify() {
    //婚姻状况类型
    apipublic.dictItemList("marriage_status").then((res) => {
      this.setData({
        columnsMarriageStatus: res.result,
      });
    });

    //政治面貌类型
    apipublic.dictItemList("political_outlook").then((res) => {
      this.setData({
        columnsPoliticalOutlook: res.result,
      });
    });

    //健康状况类型
    apipublic.dictItemList("health").then((res) => {
      this.setData({
        columnsHealth: res.result,
      });
    });

    //宗教信仰类型
    apipublic.dictItemList("faith").then((res) => {
      this.setData({
        columnsFaith: res.result,
      });
    });

    //经济状况类型
    apipublic.dictItemList("economics").then((res) => {
      this.setData({
        columnsEconomics: res.result,
      });
    });

    //学历类型
    apipublic.dictItemList("education").then((res) => {
      this.setData({
        columnEducation: res.result,
      });
    });

    //职业类型
    apipublic.dictItemList("occupation_type").then((res) => {
      this.setData({
        columnJobType: res.result,
      });
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
